package cst.a722wr.zyfypt_722wr.Fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import cst.a722wr.zyfypt_722wr.Activity.CollectActivity;
import cst.a722wr.zyfypt_722wr.Activity.FocusActivity;
import cst.a722wr.zyfypt_722wr.Activity.LoginActivity;
import cst.a722wr.zyfypt_722wr.R;
import cst.a722wr.zyfypt_722wr.iface.wrListener;
import cst.a722wr.zyfypt_722wr.model.ResModel;

public class MyFragment extends Fragment {
    private Button logout;
    private Button MyFocus;
    private Button Mycollect;
    private Intent intent;
    private wrListener<String> listener;
    private ResModel model;
    private SharedPreferences sp;
    private String SessionID;

    public MyFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my, container, false);

        listener = new wrListener<String>() {
            @Override
            public void onResponse(String s) {

            }
            @Override
            public void onFail(String msg) {
            }
        };

        logout = (Button) view.findViewById(R.id.my_logout);
        logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sp = getActivity().getSharedPreferences("ME", Context.MODE_PRIVATE);
                SessionID = sp.getString("session_id", null);
                model = new ResModel("gson");
                model.logout(SessionID, listener);
                intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
                getActivity().finish();
            }
        });

        MyFocus = (Button) view.findViewById(R.id.my_focus);
        MyFocus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(getActivity(), FocusActivity.class);
                startActivity(intent);
            }
        });

        Mycollect = (Button) view.findViewById(R.id.my_collect);
        Mycollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(getActivity(), CollectActivity.class);
                startActivity(intent);
            }
        });

    return view;
    }

}
